import { Controller } from "../../mvc/core/Controller";
import { Dispatcher } from "../../mvc/core/Dispatcher";
import { EventName } from "../mvc/EventName";
import { NetDispatcher } from "../../mvc/core/NetDispatcher";
import { EPublicCommand } from "../../../Message/Command/EPublicCommand";
import { DataEvent } from "../events/DataEvent";
import { MessageBlock } from "../../../Framework/MQ/MessageBlock";
import { SDominionPlayerScores } from "../../../Message/Public/SDominionPlayerScores";
import { IView } from "../../mvc/interfaces/IView";
import { DominionWarRankModules } from "../../../modules/DominionWarRankModules";
import { GameProxy } from "../mvc/GameProxy";
//class DomWarRankController
    
    export  class DomWarRankController extends Controller
    {
       

        protected /* override */ initServer(): void
        {
            Dispatcher.addEventListener(EventName.OnOpenDomWarRank, this.openWarRank);
            Dispatcher.addEventListener(EventName.LeaveDomWarCopy, this.onLeaveDomWar);
            NetDispatcher.addCmdListener(EPublicCommand._ECmdPublicDominionPlayerResult, this.onScoreListUpdate);
            NetDispatcher.addCmdListener(EPublicCommand._ECmdPublicDominionClose, this.onDomBattleClose);
            return;
        }

        /* internal  */onLeaveDomWar(arg1: DataEvent): void
        {
            if (!this.module.isHide) 
            {
                this.module.hide();
            }
            return;
        }

        /* internal  */onDomBattleClose(arg1=null): void
        {
            this.module.hide();
            return;
        }

        /* internal  */onScoreListUpdate(arg1: MessageBlock): void
        {
            var loc1=arg1.messageBase as SDominionPlayerScores;
            cache.dominion.sPlayerScores = loc1;
            if (this.module.isHide) 
            {
                this.module.show();
            }
            this.module.update(cache.dominion.playerScores);
            return;
        }

        protected /* override */ initView(): IView
        {
            if (!this._view) 
            {
                this._view = new DominionWarRankModules();
            }
            return this._view;
        }

        /* internal  */get module(): DominionWarRankModules
        {
            return this.initView() as DominionWarRankModules;
        }

        /* internal  */openWarRank(arg1: DataEvent): void
        {
            GameProxy.copy.getDominionScoreList();
            return;
        }
    }
